﻿@model RedSand.Site.Models.ProductInfo
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $('#choose-other-image').rsAjaxUpload({
            url: '/product/addimage?pid=@Model.ProductID',
            target :'#product-other-images',
            beforeSubmit: function (arr, form) {
                var filename = form.find('input').val().trim();
                var filefilter = ".jpg|.png|.bmp|.gif|.jpeg";
                var ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
                if (filefilter.indexOf(ext) < 0) {
                    showMessage("File không đúng định dạng");
                    return false;
                }
                $('#choose-other-image-loading').show();
            },
            success: function (data) {
                $('#choose-other-image-loading').hide();
            },
            error: function (data) {
                $('#choose-other-image-loading').hide();
                showMessage("File lỗi hoặc vượt quá dung lượng cho phép (4M)");
            }
        });
    });

</script>

<div class="dialog" title="Cập nhật thông tin" style="width: 810px;">
    @using (Ajax.BeginForm(AdminAjaxOptions.UpdateRecord))
    {
        <div class="dialog-content">
            @Html.HiddenFor(model => model.ProductID)
            @Html.HiddenFor(model => model.Views)
            <div style="float: left; width: 630px">
                <div class="form-cell" style="width: 620px">
                    @Html.LabelFor(model => model.Name)
                    @Html.EditorFor(model => model.Name)
                </div>
                <div class="form-cell">
                    @Html.LabelFor(model => model.Type)
                    @Html.DropDownListFor(model => model.Type, DropDownListHelper.GetProductTypeList(true))
                </div>
                <div class="form-cell">
                    @Html.LabelFor(model => model.Status)
                    @Html.DropDownListFor(model => model.Status, DropDownListHelper.GetStatusList(false))
                </div>
                <div class="form-cell">
                    @Html.LabelFor(model => model.IsHot)
                    @Html.DropDownListFor(model => model.IsHot, DropDownListHelper.GetProductHotList(false))
                </div>
                <div class="form-cell" style="width: 620px">
                    @Html.LabelFor(model => model.Image)
                    @Html.HiddenFor(model => model.Image)
                    <input type="text" id="choose-avatar" name="NewImage" class="choose-file" style="width: 496px" />
                </div>
            </div>
            <div style="float: left; width: 150px; margin-top: 15px">
                <img id="upload-image-preview" alt="" src="@Model.Image" width="150" />
            </div>
            <div class="form-cell" style="width: 100%;">
                @Html.LabelFor(model => model.Description)
                @Html.TextAreaFor(model => model.Description)
            </div>
            <div class="form-cell" style="width: 100%">
                <label>
                    Thông tin chi tiết</label>
                @Ajax.ActionLink("Thêm tab", "createTab", new { id = Model.ProductID }, new AjaxOptions { UpdateTargetId = "tab-edit-wrap", OnSuccess = "edit_tab_click", OnFailure = "ajax_failure" }, new { @class = "button", style = "margin:2px 0" })
                <div id="tabs-wrap" style="min-height: 300px;">
                    @Html.Action("Tab", new { id = Model.ProductID })
                </div>
            </div>
            <div class="form-cell" style="width: 100%">
                <label>
                    Hình ảnh khác</label>
                <input type="button" value="Thêm hình ảnh" id="choose-other-image" style="margin:2px 0 5px" />
                <div id="product-other-images">
                    @Html.Action("ListImage", new { pid = Model.ProductID, images = Model.OtherImages })
                </div>
            </div>
        </div>
        <div class="dialog-footer">
            <input type="submit" value="@Html.Translate("Save")" />
            <input type="button" value="@Html.Translate("Cancel")" onclick="closeDialog('.dialog')" />
        </div>
    }
    <div id="tab-edit-wrap" style="display:none"></div>
</div>
